package com.swss.g.assets.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.swss.g.assets.bean.Asset;
import com.swss.g.assets.bean.AssetCardSearch;
import com.swss.g.assets.bean.AstFinAudit;
import com.swss.g.assets.bean.AstRange;
import com.swss.g.assets.dao.AssetDAO;
import com.swss.g.assets.dao.ChangeAssetDAO;
import com.swss.g.assets.service.AssetService;
import com.swss.g.base.impl.BaseServiceImpl;
import com.swss.g.dept.bean.Dept;
import com.swss.g.sys.bean.GBCode;
import com.swss.g.sys.dao.GmkDAO;
import com.swss.g.sys.service.CurrentPeriodService;
import com.swss.g.sys.service.FuncService;
import com.swss.util.BeanUtils;
import com.swss.util.DoDate;
import com.swss.util.HqlUtil;
import com.swss.util.Pagination;

public class AssetServiceImpl extends BaseServiceImpl<Asset> implements
		AssetService {

	private AssetDAO assetDao;
	private ChangeAssetDAO changeAssetDao;
	private GmkDAO gmkDao;
	private CurrentPeriodService currentPeriodService;
	private FuncService funcService;

	public AssetDAO getAssetDao() {
		return assetDao;
	}

	public void setAssetDao(AssetDAO assetDao) {
		this.setBaseDao(assetDao);
		this.assetDao = assetDao;
	}

	public GmkDAO getGmkDao() {
		return gmkDao;
	}

	public void setGmkDao(GmkDAO gmkDao) {
		this.gmkDao = gmkDao;
	}
    /**
     * 增加资产
     */
	public void addAsset(Asset asset) throws Exception {
		// TODO Auto-generated method stub
		// 获取系统阶段 0.建账阶段 1.维护账阶段
		boolean sysstates = this.getFuncService().findSystateName("sysstates").getFuncFlag() == 0 ? true : false;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		String strBuyDate = sdf.format(asset.getBuyDate());

		String astNo[] = this.getCurrentPeriodService().getNo(
				asset.getAstMark().toCharArray()[0], sysstates, strBuyDate,
				asset.getBatchCount());
		// 设置入账时间
		if (sysstates) {
			asset.setRecordDate(asset.getBuyDate());
		} else {
			asset.setRecordDate(new DoDate().getDate(new Date()));
		}
		// 计算 金额
		if (asset.getAstCount() > 1)
			asset.setAmount(asset.getPrice() * asset.getAstCount());
		else
			asset.setAmount(asset.getPrice());
		// 设置asset对象基础信息
		asset = this.getResponseAst(asset);
		if (asset.getBatchCount() == 1) {
			asset.setAstNo(astNo[0]);
			asset.setAstEndNo(astNo[0]);
			asset.setAstNoRange(astNo[0] + "-" + astNo[0]);

			this.assetDao.save(asset);
		} else {
			List<Asset> assetList = new ArrayList<Asset>();
			Asset ast = null;
			for (int i = 0; i < asset.getBatchCount(); i++) {
				ast = new Asset();
				BeanUtils.copyProperties(asset, ast);
				ast.setAstNo(astNo[i]);
				ast.setAstEndNo(astNo[astNo.length - 1]);
				ast.setAstNoRange(astNo[0] + "-" + astNo[astNo.length - 1]);
				ast.setAduit(1);
				ast.setBatchCount(1);
				assetList.add(ast);
			}
			this.assetDao.saveAll(assetList);
		}
	}

	public CurrentPeriodService getCurrentPeriodService() {
		return currentPeriodService;
	}

	public void setCurrentPeriodService(
			CurrentPeriodService currentPeriodService) {
		this.currentPeriodService = currentPeriodService;
	}

	public FuncService getFuncService() {
		return funcService;
	}

	public void setFuncService(FuncService funcService) {
		this.funcService = funcService;
	}

	public void goFirstAduit(Asset asset) throws Exception {
		// TODO Auto-generated method stub

	}

	public ChangeAssetDAO getChangeAssetDao() {
		return changeAssetDao;
	}

	public void setChangeAssetDao(ChangeAssetDAO changeAssetDao) {
		this.changeAssetDao = changeAssetDao;
	}

	@SuppressWarnings("unchecked")
	public List<Pagination> findNotAduitAst(Asset asset) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
    /**
     * 登记管理查询
     */
	@SuppressWarnings("unchecked")
	public Pagination findAstByExample(Pagination pagination, Asset asset,AstRange astRange,String deptNo)
			throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		String hql = "FROM Asset a,Dept d,GBCode g WHERE a.deptNo=d.deptNo AND a.gbClassNo=g.ascNo AND (a.aduit=1 OR a.aduit=0)"
				+ HqlUtil.bean2HqlLike(asset, "a");
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
		if (!deptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + deptNo.trim() + "%'";
		}
		List list = this.getAssetDao().findByHql(
				hql + " ORDER BY a." + pagination.getOrderBy() + " "+ pagination.getOrderType(), pagination);
		List<Asset> assetList = new ArrayList();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			ast.setGbCode((GBCode) obj[2]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql,"a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql,"a"));
		return pagination;
	}

	@SuppressWarnings("unchecked")
	public Pagination findAstFinByExample(Pagination pagination, Asset asset,AstRange astRange,
			String DeptNo) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		String hql = "FROM Asset a,Dept d WHERE a.deptNo=d.deptNo AND (a.aduit=3 OR a.aduit=2)"+HqlUtil.bean2HqlLike(asset,"a");;
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
		if (!DeptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + DeptNo.trim() + "%'";
		}
		List list = this.getAssetDao().findByHql(hql + " ORDER BY a." + pagination.getOrderBy() + " "+ pagination.getOrderType(), pagination);
		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql, "a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql, "a"));
		return pagination;
	}

	public int astFinAuditUpdate(AstFinAudit astFinAudit, String auditNoArray)
			throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.updateAstFinAudit(assetList, astFinAudit))
			return 0;
		else
			return 1;
	}

	public int astFinAuditBack(String auditNoArray, String returreas)
			throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.backAstFinAudit(assetList, returreas))
			return 0;
		else
			return 1;
	}

	@SuppressWarnings("unchecked")
	public Pagination findthroughFinByExample(Pagination pagination,
			Asset asset,AstRange astRange,String DeptNo) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		String hql = "FROM Asset a,Dept d WHERE a.deptNo=d.deptNo AND (a.aduit=5 OR a.aduit=4)"+HqlUtil.bean2HqlLike(asset,"a");
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
		if (!DeptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + DeptNo.trim() + "%'";
		}
		List list = this.getAssetDao().findByHql(
				hql + " ORDER BY a." + pagination.getOrderBy() + " "
						+ pagination.getOrderType(), pagination);

		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql,"a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql,"a"));
		return pagination;
	}

	public int astFinthroughAudit(String auditNoArray) throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.throughAstFinAudit(assetList))
			return 0;
		else
			return 1;
	}

	@SuppressWarnings("unchecked")
	public Pagination findAstLastByExample(Pagination pagination, Asset asset,AstRange astRange,
			String deptNo) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		if (asset != null) {
			if (asset.getAstName() != null) {
				if (!asset.getAstName().equals("") && !asset.getGbClassNo().equals("")) {
					asset.setGbClassNo("");
				}
			}
		}
		String hql = "FROM Asset a,Dept d WHERE a.deptNo=d.deptNo AND (a.aduit=5 OR a.aduit=4)"
				+ HqlUtil.bean2HqlLike(asset, "a");
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
		if (!deptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + deptNo.trim() + "%'";
		}
		// System.out.println(hql);
		List list = this.getAssetDao().findByHql(
				hql + " ORDER BY a." + pagination.getOrderBy() + " "
						+ pagination.getOrderType(), pagination);

		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql, "a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql, "a"));
		return pagination;
	}

	public int astLastAuditUpdate(String auditNoArray) throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.astLastAuditUpdate(assetList))
			return 0;
		else
			return 1;
	}

	public int astLastAuditBack(String auditNoArray, String returreas)
			throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.backAstLastAudit(assetList, returreas))
			return 0;
		else
			return 1;
	}

	@SuppressWarnings("unchecked")
	public Asset findOneById(Integer id) throws Exception {
		// TODO Auto-generated method stub

		StringBuffer hql = new StringBuffer(
				"FROM Asset a,Dept d,GBCode g WHERE a.deptNo=d.deptNo AND a.gbClassNo=g.ascNo");

		hql.append(" AND a.id=" + id);

		List list = this.getAssetDao().findByHql(hql.toString());

		Object[] obj = (Object[]) list.get(0);
		Asset ast = (Asset) obj[0];
		ast.setDept((Dept) obj[1]);
		ast.setGbCode((GBCode) obj[2]);

		return ast;
	}
    /**
     * 资产初审查询
     */
	@SuppressWarnings("unchecked")
	public Pagination findAstFirstByExample(Pagination pagination, Asset asset,AstRange astRange,
			String deptNo) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		if (asset != null) {
			if (asset.getAstName() != null) {
				if (!asset.getAstName().equals("")
						&& !asset.getGbClassNo().equals("")) {
					asset.setGbClassNo("");
				}
			}
		}
		String hql = "FROM Asset a,Dept d WHERE a.deptNo=d.deptNo AND (a.aduit=0 OR a.aduit=1)"
				+ HqlUtil.bean2HqlLike(asset, "a");
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
		if (!deptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + deptNo.trim() + "%'";
		}
		List list = this.getAssetDao().findByHql(
				hql + " ORDER BY a." + pagination.getOrderBy() + " "
						+ pagination.getOrderType(), pagination);

		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql, "a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql, "a"));
		return pagination;
	}

	/**
	 * 资产登记初审
	 */
	public int astFirstAuditUpdate(String auditNoArray) throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		for (int i = 0; i < auditNo.length; i++) {
			asset = new Asset();
			asset.setId(Integer.parseInt(auditNo[i]));
			assetList.add(asset);
		}
		if (this.assetDao.astFirstAuditUpdate(assetList))
			return 0;
		else
			return 1;
	}

	/**
	 * 批量删除登记资产
	 */
	public int astDeleteAll(String auditNoArray) throws Exception {
		// TODO Auto-generated method stub
		String auditNo[] = auditNoArray.split(",");
		Asset asset = null;
		List<Asset> assetList = new ArrayList<Asset>();
		try {
			for (int i = 0; i < auditNo.length; i++) {
				asset = this.assetDao.get(Integer.parseInt(auditNo[i]));
				assetList.add(asset);
			}
			this.assetDao.deleteAll(assetList);
		} catch (Exception e) {
			e.printStackTrace();
			return 1;
		}
		return 0;
	}

	/**
	 * 设置asset对象基础信息
	 * 
	 * @param asset
	 * @return 处理后的asset
	 * @throws Exception
	 */
	public Asset getResponseAst(Asset asset) throws Exception {

		Date StrTodate = new DoDate().getStrToDate("1990-01-01");
		// 设置基础信息
		asset.setInputDate(new DoDate().getDate(new Date()));
		asset.setJzlx("0");
		asset.setJfly("0");
		asset.setCgxs("0");
		asset.setCzfs("0");
		asset.setApplicant("");
		asset.setApplicantDate(new DoDate().getDate(new Date()));
		asset.setLjzje(0.00);
		asset.setZjcz(0.00);
		asset.setJz(0.00);
		// 原始审核标记
		asset.setFstAdt("0");
		asset.setFstAdtName("");
		asset.setFstAdtDate(StrTodate);
		asset.setSndAdt("0");
		asset.setFinAdt("0");
		asset.setFinVoucher("");
		asset.setFinAdtDate(StrTodate);
		asset.setFinAdtName("");
		asset.setFinAccount("0");
		asset.setFinAdvice("");
		// 清查内容
		asset.setQcfs("0");
		asset.setQcrq(StrTodate);
		asset.setQcyc("");
		asset.setTableType("0");// 审批单类型 报表打印时使用
		asset.setSuperUnitNo("");// 上级单位号

		asset.setReturperson("");
		asset.setReturtime(StrTodate);
		asset.setRetureas("");

		return asset;
	}
    /**
     * 通过单据号返回数据条数
     */
	@SuppressWarnings("unchecked")
	public Pagination findListAstByDanJuNo(Pagination pagination,
			String danJuNo, int type) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		String hql = "";
		if (type == 1) {
			hql += " SELECT COUNT(*) FROM Asset a Where a.danJuNo='" + danJuNo
					+ "' GROUP BY a.astNoRange";
			pagination.setRowcount(this.getAssetDao().findByHql(hql).size());
		} else {
			hql += " SELECT COUNT(*) FROM ChangeAsset chagea Where chagea.chagedanJuNo='"
					+ danJuNo + "' GROUP BY chagea.astNo";
			pagination.setRowcount(this.getChangeAssetDao().findByHql(hql)
					.size());
		}
		// System.out.println(hql);
		return pagination;
	}

	@SuppressWarnings("unchecked")
	public Pagination findExcelExportByExample(Pagination pagination,
			Asset asset, String deptNo, int findType) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		if (asset == null)
			asset = new Asset();
		String hql = "FROM Asset a,Dept d WHERE a.deptNo=d.deptNo";
		if (!deptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + deptNo.trim() + "%'";
		}
		if (findType == 1) {
			hql += " AND (a.aduit=0 or a.aduit=1)";
		} else {
			hql += " AND a.aduit=7";
		}
		hql += HqlUtil.bean2HqlLike(asset, "a");
		List list = this.getAssetDao().findByHql(
				hql + " ORDER BY a." + pagination.getOrderBy() + " "
						+ pagination.getOrderType(), pagination);

		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];
			ast.setNowStatus(this.gmkDao.findSomFieldByName("现状", ast.getXz()
					.trim()));
			ast.setFundSub(this.gmkDao.findSomFieldByName("经费来源", ast.getJfly()
					.trim()));
			ast.setUseDir(this.gmkDao.findSomFieldByName("使用方向", ast.getSyfx()
					.trim()));
			ast.setAstSource(this.gmkDao.findSomFieldByName("资产来源", ast
					.getZcly().trim()));
			ast.setChargeOffDept(this.gmkDao.findSomFieldByName("拟核销财务科室", ast
					.getFinDeptName().trim()));
			ast.setAstClassName(this.gmkDao.findSomFieldByName("资产类别", ast
					.getAstClass().trim()));
			ast.setFinAccountName(this.gmkDao.findSomFieldByName("财务账户", ast
					.getFinAccount().trim()));

			ast.setDept((Dept) obj[1]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql, "a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql, "a"));
		return pagination;
	}

	@SuppressWarnings("unchecked")
	public Pagination findComplex(Pagination pagination, Asset asset,AstRange astRange,
			String deptNo, String hqlCondition) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		String hql = "FROM Asset a,Dept d,GBCode g WHERE a.deptNo=d.deptNo AND a.gbClassNo=g.ascNo AND a.aduit=7"
				+ HqlUtil.bean2HqlLike(asset, "a");

		if (!deptNo.trim().equals("00")) {
			hql += " AND a.deptNo LIKE '" + deptNo.trim() + "%'";
		}
		if (hqlCondition != null && !hqlCondition.equals("")) {
			hqlCondition = " AND (" + hqlCondition + ")";
		}else{
			hqlCondition="";
		}
		if(astRange!=null){ 
			hql+=HqlUtil.rangeHql(astRange,"a");
		}
	//	System.out.println("+++++"+hql+"***"+ hqlCondition);
		List list = this.getAssetDao().findByHql(
				hql + hqlCondition + " ORDER BY a." + pagination.getOrderBy()
						+ " " + pagination.getOrderType(), pagination);
		List<Asset> assetList = new ArrayList();

		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			Asset ast = (Asset) obj[0];

			ast.setDept((Dept) obj[1]);
			ast.setGbCode((GBCode) obj[2]);
			assetList.add(ast);
		}
		pagination.setResult(assetList);
		pagination.setRowcount(this.getAssetDao().findCount(hql+hqlCondition));
		pagination.setAstCount(this.getAssetDao().findAstCount(hql+hqlCondition, "a"));
		pagination.setAstAmount(this.getAssetDao().findAstAmount(hql+hqlCondition, "a"));
		return pagination;

	}
    /***
     * 通过卡片页面传的参数 返回数据记录条数
     * @param astCardSearch对象中 
     * searchTableType：MAIN 或 CHANGEMAIN
     * lx： 在账卡片或处置申请单 默认：0.增加单   
     * table： 资产未审或在账标记   在账5 未审1或0 
     * 
     * return pagination里包含数据条数
     */
	@SuppressWarnings("unchecked")
	public Pagination findCardByExample(Pagination pagination,
			AssetCardSearch astCardSearch) throws Exception {
		// TODO Auto-generated method stub
		if (pagination == null) {
			pagination = new Pagination();
		}
		if(astCardSearch==null){
			astCardSearch = new AssetCardSearch();  
		}
		String tableType=astCardSearch.getSearchTableType().equals("MAIN")?"a":"chageA"; 
		String columnDateName;  //记录在账或变动表中 变动时间或入账时间
		String columnDanjuName; //记录单据号或变动单据号
		String hql="SELECT COUNT(*) FROM "+astCardSearch.getSearchTableType()+" "+tableType+" WHERE 1=1";
		if(astCardSearch.getSydw()!=null){
			if(!astCardSearch.getSydw().trim().equals("00")){
				hql+=" AND "+tableType+".deptNo LIKE '"+astCardSearch.getSydw()+"%'";
			}else
				hql+=" AND 1=1";
		}
		//例如：报废表类型值不等于1
		if(!astCardSearch.getLx().equals("1")){
			columnDateName="changeDate";
			columnDanjuName="danJuNo";
		}else{
			columnDateName="recordDate";
			columnDanjuName="chagedanJuNo";
		}
		if(astCardSearch.getDanjuhao().trim()!=null){
			hql+=" AND "+tableType+"."+columnDanjuName+"='"+astCardSearch.getDanjuhao()+"'";
		}else{
			hql+=" AND "+tableType+"."+columnDanjuName+">='999999999'";
		}
		if(astCardSearch.getQsrq()!=null){
			hql+=" AND "+tableType+"."+columnDateName+">="+astCardSearch.getQsrq().trim();
		}else{
			hql+=" AND "+tableType+"."+columnDateName+">='1900-01-01'";
		}
		if(astCardSearch.getJzrq()!=null){
			hql+=" AND "+tableType+"."+columnDateName+"<="+astCardSearch.getJzrq().trim();
		}else{
			hql+=" ADN "+tableType+"."+columnDateName+"<='"+new Date()+"'";
		}
		if(astCardSearch.getBh1()!=null){
			hql+=" AND "+tableType+".astNo>="+astCardSearch.getBh1().trim();
		}else{
			hql+=" AND "+tableType+".astNo>='00000000'";
		}
		if(astCardSearch.getBh2()!=null){
			hql+=" AND "+tableType+".astNo<="+astCardSearch.getBh1().trim();
		}else{
			hql+=" AND "+tableType+".astNo<='99999999'";
		}
		if(astCardSearch.getTable().equals("")){
		   /**
		    * TODO:预留判断 是在账或变动 例如：table：aduit=0
		    */
		}else{
			
		}
		if(!astCardSearch.getLx().equals("1")){
			pagination.setRowcount(this.getChangeAssetDao().findByHql(hql).size());
		}else{
			pagination.setRowcount(this.getAssetDao().findByHql(hql).size());
		}
		return pagination;
	}

}
